﻿// JScript 文件

function getOffsetPixel()
{
    var gmapOffsetX = 0;//0.0096;
    var gmapOffsetY = 0;//0.004;

    var startLatlng = new GLatLng("39.9","116.4");
    var endLatlng = new GLatLng(39.9 + gmapOffsetY,116.4 + gmapOffsetX);
    var startPoint = gmap.fromLatLngToDivPixel(startLatlng);
    var endPoint = gmap.fromLatLngToDivPixel(endLatlng);
    var xOffsetPixel = endPoint.x - startPoint.x;
    var yOffsetPixel = endPoint.y - startPoint.y;
    return new GPoint(xOffsetPixel,yOffsetPixel);
}

    // 矩形是在地图上勾勒经纬边界的简单叠加层，其边界已指定
    // 粗细和颜色，并（可选）可以使用半透明背景颜色.
    function ImsMapOverlay(bounds, opt_img, opt_backgroundColor, opt_weight, opt_color) {
      this.bounds_ = bounds;
      this.weight_ = opt_weight || 2;
      this.color_ = opt_color || "#dcdcdc";
      this.backgroundColor_ = opt_backgroundColor || "transparent";
      this.img_ = opt_img;
    }
    

    
    ImsMapOverlay.prototype = new GOverlay();
 
    // 创建表示此矩形的 DIV.
    ImsMapOverlay.prototype.initialize = function(map) {
      // 创建表示我们的矩形的 DIV
      var div = document.createElement("div");
      if(this.weight_ > 0)
          div.style.border = this.weight_ + "px solid " + this.color_;
      div.style.position = "absolute";
      div.style.background = this.backgroundColor_;
      if(this.img_.length > 0)
      {
          var img = document.createElement("img");
          img.src = this.img_;
          div.appendChild(img);
      }
     
 
      // 我们的矩形相对于地图是平面，所以将其添加到MAP_PANE 面板，
      // 与地图本身的绘制顺序相同（即在标记阴影下方）
      map.getPane(G_MAP_MAP_PANE).appendChild(div);
 
      //this.img_ = img;
      this.map_ = map;
      this.div_ = div;
    }
 
    // 从地图面板删除 DIV
    ImsMapOverlay.prototype.remove = function() {
      this.div_.parentNode.removeChild(this.div_);
    }
 
    // 将我们的数据复制到新的矩形
    ImsMapOverlay.prototype.copy = function() {
      return new ImsMapOverlay(this.bounds_, this.weight_, this.color_,
                           this.backgroundColor_, this.opacity_, this.img_);
    }
 
    // 基于当前投影和缩放级别重新绘制矩形
    ImsMapOverlay.prototype.redraw = function(force) {
      // We only need to redraw if the coordinate system has changed
      if (!force) return;
 
      // 计算边界两个对角的 DIV 坐标，获取矩形的尺寸和位置
      var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
      var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());
 
      // 现在基于边界的 DIV 坐标放置 DIV
      this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
      this.div_.style.height = Math.abs(c2.y - c1.y) + "px";

      var offsetPoint = getOffsetPixel();
        
      this.div_.style.left = (Math.min(c2.x, c1.x) + offsetPoint.x) + "px";
      this.div_.style.top = (Math.min(c2.y, c1.y) + offsetPoint.y) + "px";
    }
    
    
    
////// 10-17日添加,测试用 --->
    function ImsMapOverlay1(bounds, opt_img, opt_backgroundColor, opt_weight, opt_color) {
      this.bounds_ = bounds;
      this.weight_ = opt_weight || 2;
      this.color_ = opt_color || "#dcdcdc";
      this.backgroundColor_ = opt_backgroundColor || "transparent";
      this.img_ = "http://zhangxiaobin/output/TEMP1_zhangxiaobin404545620.jpg"; //测试用,应该改为 opt_img
    }
    ImsMapOverlay1.prototype = new GOverlay();
    ImsMapOverlay1.prototype.initialize = function(map) {
      // 创建表示我们的矩形的 DIV
      var div = document.createElement("div");
      if(this.weight_ > 0)
          div.style.border = this.weight_ + "px solid " + this.color_;
      div.style.position = "absolute";
      div.style.background = this.backgroundColor_;
      if(this.img_.length > 0)
      {
          var img = document.createElement("img");
          img.src = this.img_;
          div.appendChild(img);
      }
     
 
      // 我们的矩形相对于地图是平面，所以将其添加到MAP_PANE 面板，
      // 与地图本身的绘制顺序相同（即在标记阴影下方）
      map.getPane(G_MAP_MAP_PANE).appendChild(div);
 
      //this.img_ = img;
      this.map_ = map;
      this.div_ = div;
    }
    // 从地图面板删除 DIV
    ImsMapOverlay1.prototype.remove = function() {
      this.div_.parentNode.removeChild(this.div_);
    }
 
    // 将我们的数据复制到新的矩形
    ImsMapOverlay1.prototype.copy = function() {
      return new ImsMapOverlay(this.bounds_, this.weight_, this.color_,
                           this.backgroundColor_, this.opacity_, this.img_);
    }
 
    // 基于当前投影和缩放级别重新绘制矩形
    ImsMapOverlay1.prototype.redraw = function(force) {
      // We only need to redraw if the coordinate system has changed
      if (!force) return;
 
      // 计算边界两个对角的 DIV 坐标，获取矩形的尺寸和位置
      var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
      var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());
 
      // 现在基于边界的 DIV 坐标放置 DIV
      this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
      this.div_.style.height = Math.abs(c2.y - c1.y) + "px";

      var offsetPoint = getOffsetPixel();
        
      this.div_.style.left = (Math.min(c2.x, c1.x) + offsetPoint.x) + "px";
      this.div_.style.top = (Math.min(c2.y, c1.y) + offsetPoint.y) + "px";
    }
    ////// <---10-17日添加,测试用
